Skip to content

refactor: migrate to native UUID - #530

Merged
kyle1morel merged 4 commits into
masterfrom
chore/migrate-to-native-uuid
Jul 22, 2026
Merged

refactor: migrate to native UUID#530
kyle1morel merged 4 commits into
masterfrom
chore/migrate-to-native-uuid

Conversation

@sanjaytkbabu

@sanjaytkbabu sanjaytkbabu commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Description

This PR removes the external uuid package dependency and migrates to Node.js native UUID functionality using crypto.randomUUID() and custom validation utilities.

PADS-861

Types of changes

Checklist

  • I have read the CONTRIBUTING doc
  • I have checked that unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown

Coverage Report (Application)

Totals Coverage
Statements: 94.63% ( 4567 / 4826 )
Methods: 96.24% ( 768 / 798 )
Lines: 97.39% ( 2758 / 2832 )
Branches: 87.04% ( 1041 / 1196 )

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown

Coverage Report (Frontend)

Totals Coverage
Statements: 53.92% ( 6691 / 12410 )
Methods: 44.77% ( 998 / 2229 )
Lines: 62.82% ( 4089 / 6509 )
Branches: 43.68% ( 1604 / 3672 )

@sanjaytkbabu
sanjaytkbabu force-pushed the chore/migrate-to-native-uuid branch from 10cb9e6 to e08bf38 Compare July 15, 2026 21:58
@sanjaytkbabu sanjaytkbabu added the deploy Requests a deployment of a semi-ephemeral instance label Jul 15, 2026
@sanjaytkbabu
sanjaytkbabu marked this pull request as ready for review July 15, 2026 22:01
@sanjaytkbabu
sanjaytkbabu requested a review from a team as a code owner July 15, 2026 22:01
@sanjaytkbabu
sanjaytkbabu force-pushed the chore/migrate-to-native-uuid branch from e08bf38 to cda0996 Compare July 15, 2026 22:07
@sanjaytkbabu
sanjaytkbabu requested a review from Copilot July 15, 2026 22:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the backend from the external uuid package to Node.js native UUID generation (crypto.randomUUID()), and replaces uuid validation/version checks with custom utilities in app/src/utils/utils.ts.

Changes:

  • Replaced uuidv4() usage across services, domains, controllers, and migrations with randomUUID().
  • Reimplemented UUID v4 validation in utils.uuidValidateV4() without the uuid package and updated unit tests accordingly.
  • Removed uuid from app/package.json dependencies and introduced NIL_UUID constant for migrations.

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
app/tests/unit/utils/utils.test.ts Updates uuidValidateV4 tests to use real UUID strings instead of mocking uuid.
app/src/utils/utils.ts Removes uuid dependency and adds regex-based UUID validation plus version extraction.
app/src/utils/constants/application.ts Adds NIL_UUID constant for nil UUID usage in migrations.
app/src/services/roadmap.ts Uses randomUUID() for noteHistoryId and noteId creation.
app/src/services/permit.ts Uses randomUUID() when generating missing permitId.
app/src/services/noteHistory.ts Uses randomUUID() for note/noteHistory ID creation.
app/src/services/login.ts Uses randomUUID() for contactId on new contacts.
app/src/services/draft.ts Uses randomUUID() for draftId.
app/src/services/accessRequest.ts Uses randomUUID() for accessRequestId.
app/src/external/ches.ts Uses randomUUID() for emailLogId generation.
app/src/domains/user.ts Uses randomUUID() for userId generation.
app/src/domains/permit.ts Uses randomUUID() for permitNoteId.
app/src/domains/housingProject.ts Uses randomUUID() for generated IDs (permits + housingProjectId).
app/src/domains/generalProject.ts Uses randomUUID() for generated IDs (permits + generalProjectId).
app/src/domains/enquiry.ts Uses randomUUID() for enquiryId generation.
app/src/domains/electrificationProject.ts Uses randomUUID() for electrification project UUID generation.
app/src/domains/activity.ts Uses randomUUID() as the source for generated 8-char activityId.
app/src/db/migrations/20260420000000_058-general-projects.ts Uses randomUUID() for inserted initiative_id.
app/src/db/migrations/20251027000000_044-system-id-change.ts Replaces uuid.NIL usage with NIL_UUID.
app/src/db/migrations/20250514000000_031-electrification.ts Uses randomUUID() for inserted initiative_id.
app/src/db/migrations/20241125000000_014-user-contacts.ts Uses randomUUID() for generated contact_id during backfill.
app/src/db/migrations/20240904000000_009-rbac.ts Uses randomUUID() for inserted initiative_id.
app/src/db/migrations/20231212000000_init.ts Uses NIL_UUID for system user IDs and randomUUID() for inserted initiative_id.
app/src/controllers/contact.ts Uses randomUUID() when contactId is absent.
app/package.json Removes the uuid dependency from app dependencies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/package.json
Comment thread app/src/utils/utils.ts Outdated
Comment thread app/src/utils/utils.ts Outdated
@sanjaytkbabu
sanjaytkbabu force-pushed the chore/migrate-to-native-uuid branch 2 times, most recently from 966941d to 1d0c47d Compare July 15, 2026 22:35
@sanjaytkbabu
sanjaytkbabu requested a review from Copilot July 15, 2026 22:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 25 out of 26 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • app/package-lock.json: Generated file
Comments suppressed due to low confidence (1)

app/package-lock.json:1648

  • In package-lock.json, some platform-specific optional packages now have identical "os"/"cpu" constraints (e.g., both the -gnu and -musl variants are linux/x64) without any "libc" discriminator. This can cause npm to install multiple mutually-exclusive native bundles on Linux, increasing install size/time and potentially complicating native binary selection in build images. Consider regenerating the lockfile with the repository's standard Node/npm toolchain so that libc/platform metadata is preserved (or otherwise ensure platform-specific packages remain properly constrained).

Comment thread app/src/utils/utils.ts Outdated
@sanjaytkbabu
sanjaytkbabu force-pushed the chore/migrate-to-native-uuid branch from 1d0c47d to cd7162f Compare July 15, 2026 23:14
@sanjaytkbabu sanjaytkbabu added deploy Requests a deployment of a semi-ephemeral instance and removed deploy Requests a deployment of a semi-ephemeral instance labels Jul 16, 2026

import type { Knex } from 'knex';

const NIL_UUID = '00000000-0000-0000-0000-000000000000';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be a app wide constant

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a holdover from when the system id was nil. We shouldn't be using nil elsewhere anymore.

Signed-off-by: Sanjay Babu <sanjaytkbabu@gmail.com>
Signed-off-by: Sanjay Babu <sanjaytkbabu@gmail.com>
…d of the uuid package

Signed-off-by: Sanjay Babu <sanjaytkbabu@gmail.com>
Signed-off-by: Sanjay Babu <sanjaytkbabu@gmail.com>
@sanjaytkbabu
sanjaytkbabu force-pushed the chore/migrate-to-native-uuid branch from cd7162f to 41ebc94 Compare July 22, 2026 20:58
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed for 'nr-permitconnect-navigator-service app'

Failed conditions
7.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed for 'nr-permitconnect-navigator-service frontend'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
100.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@kyle1morel
kyle1morel merged commit 5e75799 into master Jul 22, 2026
21 of 22 checks passed
@kyle1morel
kyle1morel deleted the chore/migrate-to-native-uuid branch July 22, 2026 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deploy Requests a deployment of a semi-ephemeral instance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants